<!DOCTYPE html>
<html lang="zh-CN" xmlns:th="http://www.thymeleaf.org">
<head th:include="admin/head :: head" th:with="title=币种信息添加">
<body>
<div class="layuimini-container">
    <div class="layuimini-main">
        <form class="layui-form" id="uploadForm" action="" lay-filter="formfilter">
            <div class="layui-form-item">
                <label class="layui-form-label"><span style="color: red">*</span>名称:</label>
                <div class="layui-input-inline">
                    <input type="text" id="name" name="name"  lay-verify="required|name" autocomplete="off" placeholder="名称" class="layui-input" th:value="${m.name}">
                </div>
                <label class="layui-form-label"><span style="color: red">*</span>状态:</label>
                <div class="layui-input-inline">
                    <input type="checkbox" th:checked="${m.status==1}" lay-filter="statusShow" lay-skin="switch" lay-text="ON|OFF">
                    <input type="hidden" id="status" name="status" th:value="${m.status}">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">图片地址:</label>
                <div class="layui-input-inline">
                    <input type="file" name="file"  class="layui-input">
                </div>
                <label class="layui-form-label"><span style="color: red">*</span>位置:</label>
                <div class="layui-input-inline">
                    <input type="text" id="position" name="position"  lay-verify="required|position" autocomplete="off" placeholder="位置" class="layui-input" th:value="${m.position}">
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <input type="hidden" name="id"  th:value="${m.id}">
                    <button class="layui-btn" lay-submit="" lay-filter="formSubmit">立即提交</button>
                </div>
            </div>
        </form>
    </div>
</div>

<script>


    layui.use(['layedit', 'layer', 'jquery','liuQi'], function () {
        var form = layui.form,
            liuQi = layui.liuQi,
            laydate = layui.laydate;

        form.on('switch(statusShow)', function(data){
            $("#status").val(this.checked?1:0);
        });
        form.render();

        //自定义验证规则
        form.verify({
            //radio验证
            otherReq: function(value,item){
                var $ = layui.$;
                var verifyName=$(item).attr('name')
                    , verifyType=$(item).attr('type')
                    ,formElem=$(item).parents('.layui-form')//获取当前所在的form元素，如果存在的话
                    ,verifyElem=formElem.find('input[name='+verifyName+']')//获取需要校验的元素
                    ,isTrue= verifyElem.is(':checked')//是否命中校验
                    ,focusElem = verifyElem.next().find('i.layui-icon');//焦点元素
                if(!isTrue || !value){
                    //定位焦点
                    focusElem.css(verifyType=='radio'?{"color":"#FF5722"}:{"border-color":"#FF5722"});
                    //对非输入框设置焦点
                    focusElem.first().attr("tabIndex","1").css("outline","0").blur(function() {
                        focusElem.css(verifyType=='radio'?{"color":""}:{"border-color":""});
                    }).focus();
                    return '必填项不能为空';
                }
            },
            name: function (value) {
            },
            pic: function (value) {
            },
            position: function (value) {
            },
            status: function (value) {
            },
        });
        //监听提交
        form.on('submit(formSubmit)', function (data) {
            var formData = new FormData($('#uploadForm')[0]);
            liuQi.ajaxUpload("/admin/currency/updateP",formData,"",
                function (data) {
                    //关闭
                    parent.layer.msg(data.msg);
                    parent.layui.table.reload('currentTableId');
                    var index = parent.layer.getFrameIndex(window.name);
                    parent.layer.close(index);
                }
            );
            return false;
        });
    });
</script>

</body>
</html>